//
//  CZQGiftCollectionViewCell.m
//  Project_A
//
//  Created by dlios on 15-7-17.
//  Copyright (c) 2015年 zhoukaidong. All rights reserved.
//

#import "CZQGiftCollectionViewCell.h"
#import "UIImageView+WebCache.h"

#define WIDTH self.contentView.frame.size.width / 172
#define HEIGHT self.contentView.frame.size.height / 200

@implementation CZQGiftCollectionViewCell
- (void)dealloc
{
    [_titleLabel release];
    [_titleImg release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.titleImg = [[[UIImageView alloc] init] autorelease];
//        self.backgroundColor = [UIColor cyanColor];
        self.titleImg.layer.cornerRadius = 10 * WIDTH;
        self.titleImg.layer.masksToBounds = YES;
        [self.contentView addSubview:self.titleImg];
        
        self.titleLabel = [[[UILabel alloc] init] autorelease];
//        self.backgroundColor = [UIColor yellowColor];
        [self.titleLabel setLineBreakMode:NSLineBreakByTruncatingMiddle];
        self.titleLabel.textColor = [UIColor whiteColor];
//        [self.titleLabel setFont:[UIFont systemFontOfSize:17 * WIDTH]];
        [self.contentView addSubview:self.titleLabel];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    self.titleImg.frame = CGRectMake(0 * WIDTH, 0* HEIGHT, 172 * WIDTH, 200 * HEIGHT);
    self.titleLabel.frame = CGRectMake(12 * WIDTH, 170 * HEIGHT, 168 * WIDTH, 30 * HEIGHT);
}
- (void)setModel:(CZQHomeModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    [self.titleImg setImageWithURL:[NSURL URLWithString:model.cover_image_url]];
    self.titleLabel.text = model.title;
}


@end
